//package design.mode.dispatcher.util.excel;
//
//import design.mode.dispatcher.bean.Report;
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//public class ReadExcel {
//    public static void main(String[] args) {
//        Map<String, List<Report>> reportList = Report.getReportList();
//        readExcel(reportList);
//    }
//    public static void readExcel(Map<String, List<Report>> reportList){
//        try {
//            String filePath = "D:\\download\\产品信息.xlsx";
//            FileInputStream file = new FileInputStream(filePath);
//            Workbook workbook = new XSSFWorkbook(file);
//            FileOutputStream fileOut = new FileOutputStream(filePath);
//            Sheet sheet = workbook.getSheetAt(0); // 假设我们要读取第一个工作表
//            int rowCount = sheet.getLastRowNum(); // 获取总行数
//            int columnIndex=0;
//            for (int i = sheet.getFirstRowNum()+2; i <= rowCount; i++) {
//                Row row = sheet.getRow(i);
//                if (row == null) {
//                    row = sheet.createRow(i);
//                }
//
//                Cell cell1 = row.getCell(0, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
//                Cell cell2 = row.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
//
//                String value1 = (cell1 == null) ? "" : cell1.getStringCellValue();
//                String value2 = (cell2 == null) ? "" : cell2.getStringCellValue();
//                String key = value1+"_"+value2;
//                int rowIndex = cell1.getRowIndex();
//                 columnIndex = cell2.getColumnIndex() +1;
//                for (List<Report> value : reportList.values()) {
//                    Map<String, Report> collect = value.stream().collect(Collectors.toMap(report -> report.getKpiName() +"_"+ report.getKpiType(), report -> report));
//                    if(collect.containsKey(key)){
//                        columnIndex++;
//                        // 创建新的空白单元格
//                        Row dataRow = sheet.createRow(rowIndex);
//                        Cell newCell = dataRow.createCell(columnIndex);
//                        System.out.println("当前行：" + rowIndex);
//                        System.out.println("当前列" + columnIndex);
//                        Report report = collect.get(key);
//                        newCell.setCellValue(report.getDeptName());
//                        columnIndex++;
//                        newCell.setCellValue(report.getDeptId());
//                        columnIndex++;
//                        newCell.setCellValue(report.getSalesAmount());
//                        columnIndex++;
//                        newCell.setCellValue(report.getZzzAmount());
//                        columnIndex++;
//                        newCell.setCellValue(report.getPercent());
//                        columnIndex++;
//                        newCell.setCellValue(report.getGroupId());
//                    }
//                    columnIndex = cell2.getColumnIndex() +1;
//                    rowIndex++;
//                }
//            }
//            workbook.write(fileOut);
//            fileOut.flush();
//            workbook.close();
//            fileOut.close();
//        } catch (Exception  e) {
//            e.printStackTrace();
//        }
//    }
//
//}
